package com.lemon.smartsafetynew.ui.adapter.monitor;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.entity.monitor.MonitorMenu;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Andrew on 2018/3/17.
 */

public class MonitorMenuAdapter extends LemonRcvAdapter<MonitorMenu> {

    private RecyclerTClickListener<MonitorMenu> mListener;

    public MonitorMenuAdapter(@Nullable List<MonitorMenu> data,
                              RecyclerTClickListener<MonitorMenu> mListener) {
        super(data);
        this.mListener = mListener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new MenuItem();
    }

    public class MenuItem implements AdapterItem<MonitorMenu> {

        private MonitorMenu data;
        private int pos;

        @Bind(R.id.label_icon)
        ImageView labelIcon;
        @Bind(R.id.label_name)
        TextView labelName;
        @Bind(R.id.ripple)
        LinearLayout ripple;

        @Override
        public int getLayoutResId() {
            return R.layout.item_main_panel_new;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {
            ripple.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(data, pos);
                }
            });
        }

        @Override
        public void handleData(MonitorMenu monitorMenu, int position) {

            data = monitorMenu;
            pos = position;

            labelIcon.setImageResource(monitorMenu.getImageId());
            labelName.setText(monitorMenu.getMenuName());

        }
    }
}
